macOS High Sierra (10.13)制作Windows 7安装U盘

  1. Open a Terminal (under Utilities)
  2. Convert the ISO to UDRW format hdiutil convert -format UDRW -o destination_file.img source_file.iso
  3. Run diskutil list and determine the device node assigned to your flash media (e.g., /dev/disk2)
  4. Run diskutil unmountDisk /dev/diskN (replace N with the disk number from the last command; in the previous example, N would be 2)
  5. Execute sudo dd if=/path/to/destination_file.img.dmg of=/dev/diskN bs=1m (replace /path/to/destination_file.img.dmg with the path where the image file is located; for example, ./win7.img.dmg)
    • Using /dev/rdisk instead of /dev/disk will faster, 20x
    • If you see the error dd: Invalid number '1m', you are using GNU dd. Use the same command but replace bs=1m with bs=1M
    • If you see the error dd: /dev/diskN: Resource busy, make sure the disk is not in use. Start the 'Disk Utility.app' and unmount (don't eject) the drive
  6. Run diskutil eject /dev/diskN, and remove your flash media when the command completes (this can take a few hours on slower drives)

继续阅读macOS High Sierra (10.13)制作Windows 7安装U盘

获取当前Python中site-packages的具体存放路径

很多时候,我们系统上安装了好几个版本的Python, 此时,我们往往没办法确定通过pip安装的包会存放到那个目录下的site-packages中,可以通过如下代码获取:

$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

Ubuntu 16.04 LTS系统上,这个输出是存在问题的,执行命令后输出的目录是:

/usr/lib/python2.7/dist-packages

实际上,通过pip命令安装的目录有很大一部分被安装到了

/usr/local/lib/python2.7/dist-packages

目录下。

macOS Sierra (10.12.4)下使用Android Studio打开Android Virtual Device Manager报告“/dev/kvm is not found”错误

Android Virtual Device Manager突然出现了/dev/kvm is not found这个错误,我猜测大概Hardware_Accelerated_Execution_Manager丢失了某些文件,或者没安装好HAXM

继续阅读macOS Sierra (10.12.4)下使用Android Studio打开Android Virtual Device Manager报告“/dev/kvm is not found”错误

macOS Sierra (10.12.4)下Caffe执行Python代码报告错误“Mean shape incompatible with input shape”

在执行macOS Sierra (10.12.4)下Caffe通过Python接口加载binaryproto格式的均值文件的时候,最后报告错误:

Traceback (most recent call last):
  File "analysis_memnet.py", line 29, in <module>
    detector = caffe.Detector(model_def, pretrained_model, mean=means)
  File "/Users/Source/caffe/distribute/python/caffe/detector.py", line 46, in __init__
    self.transformer.set_mean(in_, mean)
  File "/Users/Source/caffe/distribute/python/caffe/io.py", line 259, in set_mean
    raise ValueError('Mean shape incompatible with input shape.')
ValueError: Mean shape incompatible with input shape.

这个错误发生的原因是由于memnet提供的均值文件是256*256的,但是提供的配置文件却是227*227的,导致在io.py里面的代码在进行判断的时候发生异常。调整源代码中的python/caffe/io.py里面的代码:

    def set_mean(self, in_, mean):
        """
        Set the mean to subtract for centering the data.

        Parameters
        ----------
        in_ : which input to assign this mean.
        mean : mean ndarray (input dimensional or broadcastable)
        """
        self.__check_input(in_)
        ms = mean.shape
        if mean.ndim == 1:
            # broadcast channels
            if ms[0] != self.inputs[in_][1]:
                raise ValueError('Mean channels incompatible with input.')
            mean = mean[:, np.newaxis, np.newaxis]
        else:
            # elementwise mean
            if len(ms) == 2:
                ms = (1,) + ms
            if len(ms) != 3:
                raise ValueError('Mean shape invalid')
            if ms != self.inputs[in_][1:]:
                raise ValueError('Mean shape incompatible with input shape.')
        self.mean[in_] = mean

调整为:

    def set_mean(self, in_, mean):
        """
        Set the mean to subtract for centering the data.

        Parameters
        ----------
        in_ : which input to assign this mean.
        mean : mean ndarray (input dimensional or broadcastable)
        """
        self.__check_input(in_)
        ms = mean.shape
        if mean.ndim == 1:
            # broadcast channels
            if ms[0] != self.inputs[in_][1]:
                raise ValueError('Mean channels incompatible with input.')
            mean = mean[:, np.newaxis, np.newaxis]
        else:
            # elementwise mean
            if len(ms) == 2:
                ms = (1,) + ms
            if len(ms) != 3:
                raise ValueError('Mean shape invalid')
            if ms != self.inputs[in_][1:]:
                in_shape = self.inputs[in_][1:]
                m_min, m_max = mean.min(), mean.max()
                normal_mean = (mean - m_min) / (m_max - m_min)
                mean = resize_image(normal_mean.transpose((1,2,0)),in_shape[1:]).transpose((2,0,1)) * (m_max - m_min) + m_min
                #raise ValueError('Mean shape incompatible with input shape.')
        self.mean[in_] = mean

调整完成后,需要重新编译Caffe:

$ make clean
$ make
$ make pycaffe
$ make distribute

参考链接


macOS Sierra (10.12.4)下Caffe通过Python接口加载binaryproto格式的均值文件

macOS Sierra (10.12.4)下Caffe通过Python接口加载均值文件的时候,都是加载的.npy格式的文件,这个格式是Python存储的格式,跟我们经常下载到的.binaryproto格式的均值文件是不同的,这样就导致了加载问题。
.binaryprotoGoogleProtocol Buffer序列化后的数据,而.npy格式是Pythonnumpy模块序列化后的数据。

之所以会出现两种不同的存储格式,目前猜测是由于目前Python 3不能很好的支持Protocol Buffer导致的。

Python下是不能直接加载.binaryproto格式的数据的,必须进行一次转换才行,示例代码如下:

#coding=utf-8
#加载必要的库
import numpy as np
 
import sys,os

#设置当前目录
caffe_root = '/Users/Source/caffe/distribute/'
sys.path.append(caffe_root + 'python')

import caffe
os.chdir(caffe_root)

memnet_root = '/Users/Source/caffe/'
model_def =memnet_root + 'models/memnet/deploy.prototxt'
pretrained_model=memnet_root + 'models/memnet/memnet.caffemodel'
means_file=memnet_root + 'models/memnet/mean.binaryproto'

caffe.set_mode_cpu() 
blobProto=caffe.io.caffe_pb2.BlobProto()
binProtoFile=open(means_file,'rb')
blobProto.ParseFromString(binProtoFile.read())
means = caffe.io.blobproto_to_array(blobProto)[0]
binProtoFile.close()

# Make detector.
detector = caffe.Detector(model_def, pretrained_model, mean=means)

参考链接


macOS Sierra (10.12.4)编译pycaffe成功后,执行时候崩溃,错误“Segmentation fault: 11”

参照 macOS Sierra (10.12.3)编译Caffe 编译成功 Caffe 后,开始尝试使用 CaffePython 接口,执行如下命令:

$ make pycaffe

编译一切成功,但是当执行

import caffe

的时候,程序崩溃,提示如下内容:

Segmentation fault: 11

继续阅读macOS Sierra (10.12.4)编译pycaffe成功后,执行时候崩溃,错误“Segmentation fault: 11”

macOS Sierra (10.12.4)下Python通过PyAV调用FFMPEG操作视频

macOS Sierra (10.12.4)下使用Python操作视频,FFMPEG是目前来说最好的一个选择,但是没有为Python专门提供适配接口,网上搜索了比较长时间,才找到PyAV来操作FFMPEG

PyAV的文档地址在:https://mikeboers.github.io/PyAV/

代码地址在:https://github.com/mikeboers/PyAV

首先需要通过HomeBrew安装FFMPEG

$ brew install ffmpeg

接下来安装PyAV,安装方式两种:

一种是直接通过PIP来安装:

$ pip install av

另外一种是通过下载代码来手工安装

$ git clone https://github.com/mikeboers/PyAV.git
$ cd PyAV
$ python setup.py install

安装好后的例子如下:

import av
from av.frame import Frame
from av.packet import Packet
from av.stream import Stream
from av.utils import AVError
from av.video import VideoFrame

container = av.open('san.mp4')

for frame in container.decode(video=0):
    frame.to_image().save('./pyav/frame-%04d.jpg' % frame.index)

macOS Sierra (10.12.4)系统上Caffe借助现有的模型训练自己的数据集

Caffe代码中自带一些模型的例子,这些例子在源代码的models目录下,这些都是其他项目中用来训练的配置文件,学习的时候,我们没有必要完全自己从头到尾搭建自己的网络模型,而是直接使用例子中的模型,后期在这些模型上简单调整一下,一般可以满足大多数的需求。

下面我们以models/bvlc_alexnet目录下的模型配置文件为例子,训练我们自己的神经网络。

继续阅读macOS Sierra (10.12.4)系统上Caffe借助现有的模型训练自己的数据集

macOS Sierra (10.12.3)使用Eclipse IDE for C/C++ Developers结合CMake Editor编辑Linux MakeFile项目

使用macOS Sierra(10.12.3)开发C/C++项目,经常用到网上的开源项目,很多项目是直接用MakeFile来管理项目的,导致在调试,编辑项目的时候,比较麻烦,搜索了半天,才找到目前看来比较方便的方式,就是结合Eclipse IDE for C/C++ DevelopersCMake Editor的方式来进行处理。

继续阅读macOS Sierra (10.12.3)使用Eclipse IDE for C/C++ Developers结合CMake Editor编辑Linux MakeFile项目