在macOS High Sierra系统上使用Safari进行搜索的时候,总是莫名其妙的被修改搜索词,导致搜索结果驴唇不对马嘴。搜索了一下,这个锅应该是输入法导致的,最可恶的是不能拒绝输入法的推荐词汇,可以使用如下方式关闭输入法的自动英文矫正功能。
分类: macOS
Mac是苹果自1984年起以“Macintosh”开始的个人消费型计算机,如:iMac、Mac mini、Macbook air、Macbook pro、Mac pro等计算机。使用独立的Mac os系统,最新的OS X系列基于NeXT系统开发,不支持兼容。是一套完备而独立的生态系统。
macOS Sierra升级到macOS High Sierra后执行cc,git命令报错
macOS Sierra升级到macOS High Sierra后执行cc,git等命令报错,错误信息如下:
|
1 |
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun |
解决方法如下:
|
1 |
$ xcode-select --install |
参考链接
macOS High Sierra (10.13)制作Windows 7安装U盘
- Open a Terminal (under Utilities)
- Convert the ISO to UDRW format
hdiutil convert -format UDRW -o destination_file.img source_file.iso - Run
diskutil listand determine the device node assigned to your flash media (e.g., /dev/disk2) - Run
diskutil unmountDisk /dev/diskN(replace N with the disk number from the last command; in the previous example, N would be 2) - 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
- Run
diskutil eject /dev/diskN, and remove your flash media when the command completes (this can take a few hours on slower drives)
获取当前Python中site-packages的具体存放路径
很多时候,我们系统上安装了好几个版本的Python, 此时,我们往往没办法确定通过pip安装的包会存放到那个目录下的site-packages中,可以通过如下代码获取:
|
1 |
$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" |
在Ubuntu 16.04 LTS系统上,这个输出是存在问题的,执行命令后输出的目录是:
|
1 |
/usr/lib/python2.7/dist-packages |
实际上,通过pip命令安装的目录有很大一部分被安装到了
|
1 |
/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)下Caffe执行Python代码报告错误“Mean shape incompatible with input shape”
在执行macOS Sierra (10.12.4)下Caffe通过Python接口加载binaryproto格式的均值文件的时候,最后报告错误:
|
1 2 3 4 5 6 7 8 |
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里面的代码:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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 |
调整为:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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:
|
1 2 3 4 |
$ 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格式的均值文件是不同的,这样就导致了加载问题。
.binaryproto是Google的Protocol Buffer序列化后的数据,而.npy格式是Python的numpy模块序列化后的数据。
之所以会出现两种不同的存储格式,目前猜测是由于目前Python 3不能很好的支持Protocol Buffer导致的。
Python下是不能直接加载.binaryproto格式的数据的,必须进行一次转换才行,示例代码如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#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 后,开始尝试使用 Caffe 的 Python 接口,执行如下命令:
|
1 |
$ make pycaffe |
编译一切成功,但是当执行
|
1 |
import caffe |
的时候,程序崩溃,提示如下内容:
|
1 |
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:
|
1 |
$ brew install ffmpeg |
接下来安装PyAV,安装方式两种:
一种是直接通过PIP来安装:
|
1 |
$ pip install av |
另外一种是通过下载代码来手工安装
|
1 2 3 |
$ git clone https://github.com/mikeboers/PyAV.git $ cd PyAV $ python setup.py install |
安装好后的例子如下:
|
1 2 3 4 5 6 7 8 9 10 11 |
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目录下的模型配置文件为例子,训练我们自己的神经网络。