홈>
Lenet5와 비슷한 모델을 만들고칼텍 101 데이터 세트. 이 기본 모델의 예상 정확도가60 %. 그러나 내 모델의 정확도에 도달하고 있습니다90 + %이 데이터 세트에 Lenet5를 사용할 수 없어야합니다. 다음 코드 스 니펫은 데이터를 읽는 방법과 모델을 정의하는 방법 및 얻은 결과를 보여줍니다.
나는 사용하고있다tf.data Tensorflow 튜토리얼에 표시된대로 이미지를로드합니다.
# Obtain test(10%) and train size(90%)
test_size = round(0.1 * image_count)
train_size = image_count-test_size
# Take first 10% values as test_data
test_data = labeled_ds.take(test_size)
# Skip first 10%, and keep rest 90% data as train_data
train_data = labeled_ds.skip(test_size)
# Define np arrays to store images and labels (to be passed to the model)
train_images = np.empty((train_size,64,64,3), dtype=np.float32)
train_labels = np.empty((train_size,101,), dtype=np.bool_)
test_images = np.empty((test_size,64,64,3), dtype=np.float32)
test_labels = np.empty((test_size,101,), dtype=np.bool_)
# Iterating over train_data to seperate images and labels
for i,data in enumerate(train_data):
train_images[i] = data[0]
train_labels[i] = data[1]
# Iterating over test_data to seperate images and labels
for i,data in enumerate(test_data):
test_images[i] = data[0]
test_labels[i] = data[1]
# Convert numpy arrays into tensors
# Perform one-hot encoding for labels (False ->0, True -> 1)
train_images = tf.convert_to_tensor(train_images)
train_labels = tf.convert_to_tensor(train_labels, dtype=tf.int32)
test_images = tf.convert_to_tensor(test_images)
test_labels = tf.convert_to_tensor(test_labels, dtype=tf.int32)
데이터의 형태는 다음과 같습니다.
Train images shape: (7809, 64, 64, 3)
Test images shape: (868, 64, 64, 3)
Train labels shape: (7809, 101)
Test labels shape: (868, 101)
내가 정의하고있는 Lenet5 모델 :
# Define the Lenet 5 architecture as per the description
model = models.Sequential()
model.add(layers.Conv2D(32, (5, 5), activation='relu', input_shape=(64, 64, 3)))
model.add(layers.MaxPooling2D((4, 4)))
model.add(layers.Conv2D(64, (5, 5), activation='relu'))
model.add(layers.MaxPooling2D((4, 4)))
model.add(layers.Flatten())
model.add(layers.Dense(1024, input_shape=(256,), activation='relu'))
model.add(layers.Dense(84, activation='relu'))
model.add(layers.Dense(101, activation='softmax'))
model.compile(optimizer='adam',loss=tf.keras.losses.CategoricalCrossentropy(), metrics=['accuracy'])
history = model.fit(train_images, train_labels, epochs=20, validation_data=(test_images, test_labels))
관찰 된 손실 및 정확도 값 :
Train on 7809 samples, validate on 868 samples
Epoch 1/20
7809/7809 [==============================] - 17s 2ms/sample - loss: 3.8387 - accuracy: 0.2018 - val_loss: 3.3969 - val_accuracy: 0.2661
.
.
.
Epoch 19/20
7809/7809 [==============================] - 15s 2ms/sample - loss: 0.1205 - accuracy: 0.9679 - val_loss: 0.5456 - val_accuracy: 0.9136
Epoch 20/20
7809/7809 [==============================] - 15s 2ms/sample - loss: 0.1672 - accuracy: 0.9522 - val_loss: 0.5295 - val_accuracy: 0.9159
테스트 데이터가 열차 데이터에 없는지 확인했습니다.
test_images.numpy() in train_images.numpy()
# Outputs 'False'
모델이 모든 레이블을 False로 분류하지 않도록 혼동 행렬을 플로팅했습니다.
from sklearn.metrics import confusion_matrix
y_pred = model.predict_classes(test_images)
y_label = []
for i in range(len(y_pred)):
a, = np.where(test_labels[i].numpy()==1)
y_label.append(a[0])
con_mat = tf.math.confusion_matrix(labels=y_label, predictions=y_pred)
'''
Output: con_mat =
array([[2, 0, 0, ..., 0, 0, 0],
[0, 9, 0, ..., 0, 0, 0],
[0, 0, 4, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 5, 0, 0],
[0, 0, 0, ..., 0, 3, 0],
[0, 0, 0, ..., 0, 0, 2]], dtype=int32)
'''
본인은 실수를 저 지르거나 잠재적 결함을 감독하여 높은 정확도로 이어질 수 있음을 이해합니다. 모든 리드를 부탁드립니다. 감사!
- 답변 # 1
관련 자료
- gpgpu - OpenCL '비 차단'읽기는 예상보다 비용이 높습니다
- python - Keras에서 CNN 모델을 사용하여 상당히 나쁜 정확도 얻기
- c로 코딩하려고 할 때마다 [10 - 1 : error : expected identifier or ')'] 메시지가 계속 표시됩니다 누군가 해결책을 제공 할 수 있습니까?
- vue.js - '4 개의 인수가 필요하지만 typescript와 함께 vuex getter를 사용하려고하면 1 개'가 발생합니다
- python - 내 DecisionTree 모델에서 100 % 정확도 얻기
- python - Keras 바이너리 분류 모델에서 정확도가 0 인 이유는 무엇입니까?
- arrays - SQL 쿼리 — ALL 및 '='연산자를 사용하여 예상 결과를 얻지 못함
- sql - 이 프로 시저를 만들었는데 실행할 때 예상 된 결과를 얻지 못했습니다
- html - CSS 코드에서 "예상 RBRACE", "예기치 않은 RBRACE"및 "예상 LBRACE"라는 두 가지 오류가 발생합니다
- Java의 반올림 문제 이 경우 왜 예상 한 결과를 얻지 못합니까?
- linux - 종료 코드를 사용하여 if 문과 echo 프롬프트에서 예상 결과를 얻지 못했습니다
- "외부 테이블이 예상 한 형식이 아닙니다." SSIS에서 Excel 파일을 가져 오는 동안 오류가 발생했습니다.
- c - fork ()가 예상 출력을 얻지 못한 후 왜?
- python - 유형 오류 가져 오기 - 예상 문자열 또는 바이트와 유사한 객체
시험 데이터와 열차 데이터가 올바르게 분할되지 않았습니다. 'take'및 'skip'방법을 사용하면 데이터가 2로 분할되지 않았습니다.독특한세트. 테이크 앤 스킵 방법을 잘못 이해했다고 생각합니다. 모든 테스트 데이터가 아니라 대부분의 테스트 데이터가 열차 데이터, 라인에 존재하기 때문에
False를 출력합니다.