def __init__(self, network, types, shapes, output_num, strategy3=None, strategy4=None, axis=-1): super(NetWithLoss, self).__init__() self.get_next = P.GetNext(types, shapes, output_num, "") self.one_hot = P.OneHot(axis=axis).shard(strategy3) self.on_value = Tensor(1.0, ms.float32) self.off_value = Tensor(0.0, ms.float32) self.loss = P.SoftmaxCrossEntropyWithLogits().shard(strategy4) self.network = network
tensor = Tensor(input_np) ms_types.append(tensor.dtype()) return ms_types if __name__ == '__main__': data_set = test_me_de_train_dataset() dataset_size = data_set.get_dataset_size() batch_size = data_set.get_batch_size() dataset_shapes = data_set.output_shapes() np_types = data_set.output_types() dataset_types = convert_type(dataset_shapes, np_types) ds1 = data_set.device_que() get_next = P.GetNext(dataset_types, dataset_shapes, 2, ds1.queue_name) tadd = P.ReLU() class dataiter(nn.Cell): def __init__(self): super(dataiter, self).__init__() def construct(self): input_, _ = get_next() return tadd(input_) net = dataiter() net.set_train() _executor.init_dataset(ds1.queue_name, 39, batch_size, dataset_types, dataset_shapes, (), 'dataset')
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ import mindspore as ms from mindspore.ops import Primitive from mindspore.ops import operations as P get_next = P.GetNext([ms.float32], [[1, 64, 112, 112]], 1, "") tensor_move_attr = Primitive('TensorMove') tensor_move_attr.add_prim_attr("label_for_insert_stream_active", True) tensor_move = Primitive('tensor_move') cast = P.Cast() add = P.Add() class FnDict: def __init__(self): self.fnDict = {} def __call__(self, fn): self.fnDict[fn.__name__] = fn def __getitem__(self, name):
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ import mindspore as ms from mindspore.ops import Primitive from mindspore.ops import _constants as Constants from mindspore.ops import operations as P get_next = P.GetNext([ms.float32, ms.int32], [[32, 64], [32]], 2, "") memcpy_async = Primitive('memcpy_async') make_tuple = Primitive('make_tuple') tuple_getitem = Primitive(Constants.kTupleGetItem) class FnDict: def __init__(self): self.fnDict = {} def __call__(self, fn): self.fnDict[fn.__name__] = fn def __getitem__(self, name): return self.fnDict[name]
def __init__(self): super().__init__() self.get_next = P.GetNext([ms.float32, ms.int32], [[32, 64], [32]], 2, "")
def __init__(self, network, dataset_types, dataset_shapes, shared_name=''): super(NetWithTDT, self).__init__() self.get_next = P.GetNext(dataset_types, dataset_shapes, len(dataset_shapes), shared_name) self.Op_network = network