当前位置:   article > 正文

Mac下安装python使用TensorFlow训练自己的模型_mac安装tflite model maker

mac安装tflite model maker

程序猿日常

Mac下安装python使用TensorFlow训练自己的模型
  • 1

目标

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
  • 1
  • 2

常用命令

卸载指定模块

pip3 uninstall ***模块名字
  • 1

安装模块指定版本号

pip3 install --ignore-installed ***模块名字==版本号
  • 1

安装模块 tflite-model-maker

pip3 install tflite-model-maker 
  • 1

安装brew

/bin/zsh -c "$(curl -fsSL  https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
  • 1

libusb-1.0.0.dylib (no such file) 安装libusb

brew install libusb
  • 1

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
  • 1
  • 2

运行 引用的模块正常

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

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')
  • 1
  • 2
  • 3
  • 4
  • 5

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')
  • 1
  • 2
  • 3
  • 4
  • 5

数据集下载到默认缓存目录 ~/.keras

在这里插入图片描述
image_classifier.create 会报错 ssl证书验证失败

import ssl #全局取消证书验证
ssl._create_default_https_context = ssl._create_unverified_context #全局取消证书验证
  • 1
  • 2
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/446774
推荐阅读
相关标签
  

闽ICP备14008679号