<jupyter_start><jupyter_text><jupyter_code>import os
import pandas as pd
import random
import cv2
import numpy as np
import matplotlib.pyplot as plt
import pickle 
import tensorflow as tf 
from sklearn.model_selection import train_test_split
import keras
from google.colab import drive
drive.mount('/content/drive')
caminho ='./drive/My Drive/limaoP/limao/'
os.listdir(caminho)
img_array = cv2.imread(caminho+'doentes/'+"img1.jpg", cv2.IMREAD_GRAYSCALE)       
%matplotlib inline
plt.imshow(img_array)
plt.show()
def ftPlantas(caminho):

  subpasta = ['doentes', 'saudaveis']

  imagem = []
  rotulo = []

  for sub in subpasta:
    arquivos_img = os.listdir(caminho+sub)
    for imagens in arquivos_img:
      img_array = cv2.imread(caminho+sub+'/'+imagens, cv2.IMREAD_GRAYSCALE)
      img_array = cv2.resize(img_array, (30,20), interpolation = cv2.INTER_AREA)
      img_array = tf.keras.utils.normalize(img_array, axis = 1)
      img_array = img_array.reshape(-1)
      imagem.append(img_array)
      if sub == 'doentes':
        rotulo.append(1)
      else:
        rotulo.append(0)

  return np.asarray(rotulo), np.asarray(imagem) 
rotulo, caracteristicas = ftPlantas(caminho)
len(caracteristicas[0])
caracteristicas_treino, caracteristicas_teste, rotulo_treino, rotulo_test = train_test_split(caracteristicas, rotulo, test_size = 0.2, random_state = 10)
model = keras.Sequential()

model.add(keras.layers.core.Dense(512, input_shape =tuple([caracteristicas.shape[1]]), activation='sigmoid'))

model.add(keras.layers.core.Dense(64, activation='relu'))
model.add(keras.layers.core.Dense(64, activation='relu'))

model.add(keras.layers.Dropout(rate=0.5))


model.add(keras.layers.core.Dense(2, activation='sigmoid'))

model.compile(loss="sparse_categorical_crossentropy", optimizer="adam", metrics=["accuracy"])

print(model.summary())
model.fit(caracteristicas_treino, rotulo_treino, epochs=300)
model.evaluate(caracteristicas_treino, rotulo_treino)
predictions = model.predict(caracteristicas_teste)
predictions[0:5]
rotulo_pred = ["saudavel" if x[0] > x[1] else "doente" for x in predictions]
rotulo_pred[0:10]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1296037296037296, 'fraction_numerical': 0.019580419580419582, 'mean_word_length': 5.70625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '296123', 'license': 'MIT', 'n_tokens_mistral': 828, 'n_tokens_neox': 809, 'n_words': 138, 'path': 'neuralnet.ipynb', 'repo_name': 'ryangpaiva/Neural-Networks', 'size': '2145'}