  
      def initialize(self):
          """ Initialize pynvml """
          if not self.initialized:
              try:
                  pynvml.nvmlInit()
              except pynvml.NVMLError_LibraryNotFound:
                  self.initialized = True
                  return
              self.initialized = True
              self.get_device_count()
              self.get_handles()
  
      def shutdown(self):
 
</s> remove             pynvml.nvmlShutdown()
 </s> add             if not is_macos:
                pynvml.nvmlShutdown() </s> remove         try:
            self.device_count = pynvml.nvmlDeviceGetCount()
        except pynvml.NVMLError:
            self.device_count = 0
 </s> add         if is_macos:
            self.device_count = pynvx.cudaDeviceGetCount(ignore=True)
        else:
            try:
                self.device_count = pynvml.nvmlDeviceGetCount()
            except pynvml.NVMLError:
                self.device_count = 0 </s> remove import pynvml
 </s> add import platform

if platform.system() == 'Darwin':
    import pynvx
    is_macos = True
else:
    import pynvml
    is_macos = False </s> remove         try:
            driver = pynvml.nvmlSystemGetDriverVersion().decode("utf-8")
        except pynvml.NVMLError:
            driver = "No Nvidia driver found"
 </s> add         if is_macos:
            driver = pynvx.cudaSystemGetDriverVersion(ignore=True)
        else:
            try:
                driver = pynvml.nvmlSystemGetDriverVersion().decode("utf-8")
            except pynvml.NVMLError:
                driver = "No Nvidia driver found" </s> remove         self.handles = [pynvml.nvmlDeviceGetHandleByIndex(i)
                        for i in range(self.device_count)]
 </s> add         if is_macos:
            self.handles = pynvx.cudaDeviceGetHandles(ignore=True)
        else:
            self.handles = [pynvml.nvmlDeviceGetHandleByIndex(i)
                            for i in range(self.device_count)]
            if is_macos:
                try:
                    pynvx.cudaInit()
                except RuntimeError:
                    self.initialized = True
                    return
            else:
                try:
                    pynvml.nvmlInit()
                except pynvml.NVMLError_LibraryNotFound:
                    self.initialized = True
                    return
  
      def initialize(self):
          """ Initialize pynvml """
          if not self.initialized:
            if is_macos:
                try:
                    pynvx.cudaInit()
                except RuntimeError:
                    self.initialized = True
                    return
            else:
                try:
                    pynvml.nvmlInit()
                except pynvml.NVMLError_LibraryNotFound:
                    self.initialized = True
                    return
            if is_macos:
                try:
                    pynvx.cudaInit()
                except RuntimeError:
                    self.initialized = True
                    return
            else:
                try:
                    pynvml.nvmlInit()
                except pynvml.NVMLError_LibraryNotFound:
                    self.initialized = True
                    return
            if is_macos:
                try:
                    pynvx.cudaInit()
                except RuntimeError:
                    self.initialized = True
                    return
            else:
                try:
                    pynvml.nvmlInit()
                except pynvml.NVMLError_LibraryNotFound:
                    self.initialized = True
                    return
            if is_macos:
                try:
                    pynvx.cudaInit()
                except RuntimeError:
                    self.initialized = True
                    return
            else:
                try:
                    pynvml.nvmlInit()
                except pynvml.NVMLError_LibraryNotFound:
                    self.initialized = True
                    return
            if is_macos:
                try:
                    pynvx.cudaInit()
                except RuntimeError:
                    self.initialized = True
                    return
            else:
                try:
                    pynvml.nvmlInit()
                except pynvml.NVMLError_LibraryNotFound:
                    self.initialized = True
                    return
              self.initialized = True
              self.get_device_count()
              self.get_handles()
  
      def shutdown(self):
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
 Fixed face extract with dlib on OS X (#510)

* fix: gpu stat for OS X
- Use pynvx to get GPU info on OS X
- fix face extract with dlib

Issue #488 
lib/gpu_stats.py