程序猿日常
Mac下安装python使用TensorFlow训练自己的模型
目标
https://www.tensorflow.org/lite/models/modify/model_maker/image_classification?hl=zh-cn
安装Python3.8版本
下载地址双击安装
安装pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
常用命令
卸载指定模块
pip3 uninstall ***模块名字
安装模块指定版本号
pip3 install --ignore-installed ***模块名字==版本号
安装模块 tflite-model-maker
pip3 install tflite-model-maker
安装brew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
libusb-1.0.0.dylib (no such file) 安装libusb
brew install libusb
ImportError: cannot import name ‘array_record_module’ from ‘array_record.python’
git clone https://github.com/tensorflow/datasets /tmp/datasets
python3 -m pip install -e /tmp/datasets
运行 引用的模块正常
import os
import numpy as np
import tensorflow as tf
assert tf.__version__.startswith('2')
from tflite_model_maker import model_spec
from tflite_model_maker import image_classifier
from tflite_model_maker.config import ExportFormat
from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.image_classifier import DataLoader
import matplotlib.pyplot as plt
tf.keras.utils.get_file 加载网络数据集
image_path = tf.keras.utils.get_file(
'flower_photos.tgz',
'https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz',
extract=True)
image_path = os.path.join(os.path.dirname(image_path), 'flower_photos')
tf.keras.utils.get_file 加载本地数据集
file:/// 三个/从本地获取
image_path = tf.keras.utils.get_file(
'flower_photos.tgz',
'file:///Users/lang/Desktop/python/flower_photos.zip',
extract=True)
image_path = os.path.join(os.path.dirname(image_path), 'flower_photos')
数据集下载到默认缓存目录 ~/.keras
image_classifier.create 会报错 ssl证书验证失败
import ssl #全局取消证书验证
ssl._create_default_https_context = ssl._create_unverified_context #全局取消证书验证