def FeedBlob(name, arr, device_option=None): """Feeds a blob into the workspace. Inputs: name: the name of the blob. arr: either a TensorProto object or a numpy array object to be fed into the workspace. device_option (optional): the device option to feed the data with. Returns: True or False, stating whether the feed is successful. """ if type(arr) is caffe2_pb2.TensorProto: arr = utils.Caffe2TensorToNumpyArray(arr) if type(arr) is np.ndarray and arr.dtype.kind in 'SU': # Plain NumPy strings are weird, let's use objects instead arr = arr.astype(np.object) if device_option is None: device_option = scope.CurrentDeviceScope() if device_option and device_option.device_type == caffe2_pb2.CUDA: if arr.dtype == np.dtype('float64'): logger.warning( "CUDA operators do not support 64-bit doubles, " + "please use arr.astype(np.float32) or np.int32 for ints." + " Blob: {}".format(name) + " type: {}".format(str(arr.dtype)) ) name = StringifyBlobName(name) if device_option is not None: return C.feed_blob(name, arr, StringifyProto(device_option)) else: return C.feed_blob(name, arr)
def FeedBlob(name, arr, device_option=None): """Feeds a blob into the workspace. Inputs: name: the name of the blob. arr: either a TensorProto object or a numpy array object to be fed into the workspace. device_option (optional): the device option to feed the data with. Returns: True or False, stating whether the feed is successful. """ if type(arr) is caffe2_pb2.TensorProto: arr = utils.Caffe2TensorToNumpyArray(arr) if type(arr) is np.ndarray and arr.dtype.kind in 'SU': # Plain NumPy strings are weird, let's use objects instead arr = arr.astype(np.object) if device_option is None: device_option = scope.CurrentDeviceScope() if device_option and device_option.device_type == caffe2_pb2.CUDA: if arr.dtype == np.dtype('float64'): logger.warning( "CUDA operators do not support 64-bit doubles, " + "please use arr.astype(np.float32) or np.int32 for ints." + " Blob: {}".format(name) + " type: {}".format(str(arr.dtype))) name = StringifyBlobName(name) if device_option is not None: return C.feed_blob(name, arr, StringifyProto(device_option)) else: return C.feed_blob(name, arr)
def FeedBlob(name, arr, device_option=None): """Feeds a blob into the workspace. Inputs: name: the name of the blob. arr: either a TensorProto object or a numpy array object to be fed into the workspace. device_option (optional): the device option to feed the data with. Returns: True or False, stating whether the feed is successful. """ if type(arr) is caffe2_pb2.TensorProto: arr = utils.Caffe2TensorToNumpyArray(arr) if type(arr) is np.ndarray and arr.dtype.kind == 'S': # Plain NumPy strings are weird, let's use objects instead arr = arr.astype(np.object) name = StringifyBlobName(name) if device_option is not None: return C.feed_blob(name, arr, StringfyProto(device_option)) elif scope.DEVICESCOPE is not None: return C.feed_blob(name, arr, StringfyProto(scope.DEVICESCOPE)) else: return C.feed_blob(name, arr)
# Create GPU device option device_opts = caffe2_pb2.DeviceOption() if use_gpu == 0: device_opts.device_type = caffe2_pb2.CPU print('Running on CPU') else: device_opts.device_type = caffe2_pb2.HIP device_opts.hip_gpu_id = 0 print('Running on HIP') if use_gpu == 2: engine_list = ['MIOPEN', ''] C.set_global_engine_pref({caffe2_pb2.HIP : engine_list}) print('Using MIOPEN') C.feed_blob('data', img, device_opts.SerializeToString()) init_def = caffe2_pb2.NetDef() with open(INIT_NET, 'rb') as f: init_def.ParseFromString(f.read()) init_def.device_option.CopyFrom(device_opts) C.run_net_once(init_def.SerializeToString()) net_def = caffe2_pb2.NetDef() with open(PREDICT_NET, 'rb') as f: net_def.ParseFromString(f.read()) net_def.device_option.CopyFrom(device_opts) C.create_net(net_def.SerializeToString()) C.feed_blob('data', img, device_opts.SerializeToString()) ### Debug code