You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mobilenet_v2.py 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright 2021 The KubeEdge Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import mindspore as ms
  15. from mindvision.classification.models import mobilenet_v2
  16. from mindvision.dataset import DownLoad
  17. class mobilenet_v2_fine_tune:
  18. def __init__(self, base_model_url):
  19. self.network = mobilenet_v2(num_classes=2, resize=224)
  20. self.param_dict = ms.load_checkpoint(base_model_url)
  21. def get_train_network(self):
  22. filter_list = [x.name for x in self.network.head.classifier.get_parameters()]
  23. for key in list(self.param_dict.keys()):
  24. for name in filter_list:
  25. if name in key:
  26. print("Delete parameter from checkpoint: ", key)
  27. del self.param_dict[key]
  28. break
  29. ms.load_param_into_net(self.network, self.param_dict)
  30. return self.network
  31. def get_eval_network(self):
  32. ms.load_param_into_net(self.network, self.param_dict)
  33. return self.network