Imagpath


import android.app.Application;

import com.example.mr.weektwo_work.Imagbase;


public class Imagpath extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Imagbase.info(this);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import numpy import numpy as np import tensorflow as tf import matplotlib.pyplot as plt import os import cv2 as cv from sklearn.model_selection import train_test_split def getImgeAndLabels(path): #存放训练图片 facesSamples = [] #存放图片id ids = [] #存放路径和名称 imagPaths = [] for f in os.listdir(path): #连接文件夹路径和图片名称 result = os.path.join(path,f) #存入 imagPaths.append(result) face_detector = cv.CascadeClassifier(r'D:\pyh\envs\OpenCV\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml') for imagPath in imagPaths: #读取每一种图片 img = cv.imread(imagPath) PIL_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY) #获取每张图片的id 利用os.path.split的方法将路径和名称分割开 id = int(os.path.split(imagPath)[1].split('.')[0]) facesSamples.append(PIL_img) ids.append(id) return facesSamples,ids if __name__ == '__main__': path = './data/' faces,ids = getImgeAndLabels(path) x = np.array(faces,dtype = np.uint8) y = np.array(ids,dtype = np.uint8) x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=0) model = tf.keras.models.Sequential([ tf.keras.layers.Input(shape=(112, 92)), #拉平转化为一维数据 tf.keras.layers.Flatten(input_shape=(112,92)), #定义神经网络全连接层,参数是神经元个数以及使用激活函数 tf.keras.layers.Dense(200,activation='relu'), #设置遗忘率 # tf.keras.layers.Dropout(0.2), #定义最终输出(输出10种类别,softmax实现分类的概率分布) tf.keras.layers.Dense(16,activation='softmax') ]) model.compile( optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy']) print("模型*************") model.fit(x,y,epochs=80) print("成绩***********") model.evaluate(x_test,y_test) class_name = ['u1','u2','u3', 'u4','u5','u6','u7','u8','u9','u10','u11','u12','u13',] predata = cv.imread(r'./data/5.pgm') predata = cv.cvtColor(predata, cv.COLOR_RGB2GRAY) reshaped_data = np.reshape(predata, (1, 112, 92)) #预测一个10以内的数组,他们代表对10种不同服装的可信度 predictions_single = model.predict(reshaped_data) max = numpy.argmax(predictions_single) #在列表找到最大值 print(class_name[max-1]) plt.imshow(x_test[10],cmap=plt.cm.gray_r) plt.show()
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值