Home > Backend Development > Python Tutorial > If trying write AI

If trying write AI

DDD
Release: 2024-11-23 08:16:30
Original
1035 people have browsed it

We tolk a lot about new trend writting code with help AI. If you look into it, it will become obviously: AI capable of replacing small parts of modern code in companies.
Today AI much more effective in areas: detecting objects, words bots and computer vision.

If trying write AI

On picture not very hard neural network, which based on a series of convolutions and pulls. This particular design names UNet-Segmentation.

  • Some useful libraries will help to impact data for training network: numpy, pandas, matplotlib
df = pd.read_csv('data/train_masks.csv')

train_df = df[:4000]
val_df = df[4000:]

img_name, mask_rle = train_df.iloc[4]

img = cv2.imread('data/train/{}'.format(img_name))
mask = rle_decode(mask_rle)
Copy after login
  • Next step to success coding AI: copying achitecture to Python (I usually use Google Colab/Jupyter Notebook). Migth help: keras
conv_1_1 = Conv2D(32, (3, 3), padding='same')(inp) 
conv_1_1 = Activation('relu')(conv_1_1) 

conv_1_2 = Conv2D(32, (3, 3), padding='same')(conv_1_1)
conv_1_2 = Activation('relu')(conv_1_2)

pool_1 = MaxPooling2D(2)(conv_1_2)
Copy after login
  • The last one: model training. Sometimes it takes a little time (for me ~ 7 minutes) for complete all areas
model.fit_generator(keras_generator(train_df, batch_size),
              steps_per_epoch=100, 
              epochs=100, 
              verbose=1, 
              callbacks=callbacks, 
              validation_data=keras_generator(val_df, batch_size),
              validation_steps=50,
              class_weight=None,
              max_queue_size=10,
              workers=1,
              use_multiprocessing=False,
              shuffle=True,
              initial_epoch=0)
Copy after login

If trying write AI

The above is the detailed content of If trying write AI. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template