91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 29.46MB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發布日期: 2023-07-11
  • 語言: 其他
  • 標簽: python??tensorflow??keras??

資源簡介

服裝識別項目數據集與代碼

資源截圖

代碼片段和文件信息

import?tensorflow?as?tf
from?tensorflow?import?keras
import?osgzip
import?numpy?as?np
import?matplotlib.pyplot?as?plt
fashion_mnist=keras.datasets.fashion_mnist
path=‘./data‘
files=[‘train-labels-idx1-ubyte.gz‘
???????‘train-images-idx3-ubyte.gz‘
???????‘t10k-labels-idx1-ubyte.gz‘
???????‘t10k-images-idx3-ubyte.gz‘]
def?load_data(data_folderfiles):
????paths=[]
????for?fname?in?files:
????????paths.append(os.path.join(data_folderfname))
????##frombuffer將data以流的形式讀入轉化成ndarray對象
????#第一參數為stream第二參數為返回值的數據類型,第三參數指定從stream的第幾位開始讀入
????with?gzip.open(paths[0]‘rb‘)?as?lbpath:
????????y_train?=?np.frombuffer(lbpath.read()np.uint8offset=8)
????with?gzip.open(paths[1]‘rb‘)?as?imgpath:
????????x_train?=?np.frombuffer(imgpath.read()np.uint8offset=16).reshape(len(y_train)2828)
????with?gzip.open(paths[2]?‘rb‘)?as?lbpath:
????????y_test?=?np.frombuffer(lbpath.read()?np.uint8?offset=8)
????with?gzip.open(paths[3]‘rb‘)?as?imgpath:
????????x_test?=?np.frombuffer(imgpath.read()np.uint8offset=16).reshape(len(y_test)2828)
????return?(x_trainy_train)(x_testy_test)
(train_imagestrain_labels)(test_imagestest_labels)=load_data(pathfiles)
class_names?=?[‘T-shirt/top‘‘Trouser‘‘Pullover‘‘Dress‘‘Coat‘‘Sandal‘‘Shirt‘‘Sneaker‘‘Shirt‘‘Sneaker‘‘Bag‘‘Ankle?boot‘]
train_images=train_images/255.0
test_images=test_images/255.0
plt.figure(figsize=(1010))
for?i?in?range(25):
????plt.subplot(55i+1)
????plt.xticks([])
????plt.yticks([])
????plt.grid(False)
????plt.imshow(train_images[i]cmap=plt.cm.binary)
????plt.xlabel(class_names[train_labels[i]])
#?plt.show()
#建模
model=keras.Sequential([
????keras.layers.Flatten(input_shape=(2828))
????keras.layers.Dense(128activation=‘relu‘)
????keras.layers.Dense(10activation=‘softmax‘)])
#編譯訓練模型
model.compile(optimizer=‘adam‘
??????????????loss=‘sparse_categorical_crossentropy‘
??????????????metrics=[‘accuracy‘])
model.fit(train_imagestrain_labelsepochs=10)
#評估模型及預測
test_losstest_acc?=?model.evaluate(test_imagestest_labelsverbose=2)
print(‘\nTest?accuracy:‘test_acc)
predictions?=?model.predict(test_images)
print(predictions[1])
print(np.argmax(predictions[1]))
print(test_labels[1])
def?plot_image(ipredictions_arraytrue_labelimg):
????predictions_arraytrue_labelimg=predictions_arraytrue_label[i]img[i]
????plt.grid(False)
????plt.xticks([])
????plt.yticks([])
????plt.imshow(imgcmap=plt.cm.binary)
????predicted_label=np.argmax(predictions_array)
????if?predicted_label?==?true_label:
????????color?=?‘blue‘
????else:
????????color=‘red‘
????plt.xlabel(‘{}{:2.0f}%({})‘.format(class_names[predicted_label]
???????????????????????????????????????100*np.max(predictions_array)
???????????????????????????????????????class_names[true_label])
???????????????color=color)
def?plot_value_array(ipredictions_arraytrue_label):
????predictions_arraytrue_label=predictions_arraytrue_label[i]
????plt.grid(False)
????plt.xt

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????????0??2020-01-15?09:17??yi_shibie\__init__.py
?????目錄???????????0??2020-01-15?09:22??yi_shibie\data\
?????文件?????4422102??2020-01-15?09:20??yi_shibie\data\t10k-images-idx3-ubyte.gz
?????文件????????5148??2020-01-15?09:20??yi_shibie\data\t10k-labels-idx1-ubyte.gz
?????文件????26421880??2020-01-15?09:21??yi_shibie\data\train-images-idx3-ubyte.gz
?????文件???????29515??2020-01-15?09:20??yi_shibie\data\train-labels-idx1-ubyte.gz
?????文件????????3994??2020-01-15?14:20??yi_shibie\yi_shibie.py

評論

共有 條評論